<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>作用域插槽</title>
    <style>
        .active {
            background-color: skyblue;
        }
    </style>
</head>

<body>
    <div class="app">
        <hello-vue :list="teamList">
            <template slot-scope="teamData">
                <span :class="teamData.team.id === 3? 'active' : ''">{{teamData.team.tname}}</span>
            </template>
        </hello-vue>
    </div>

    <script src="./js/vue.js"></script>
    <script>
        Vue.component('hello-vue', {
            props: ['list'],
            template: `
            <div>
                <ul>
                    <li v-for="item in list" :key="item.id">
                        <slot :team="item">{{item.name}}</slot>
                    </li>
                </ul>
            </div>
            `
        })
        var xm = new Vue({
            el: '.app',
            data: {
                teamList: [
                    {
                        id: 1,
                        tname: '湖人',
                        age: 18
                    },
                    {
                        id: 2,
                        tname: '火箭',
                        age: 18
                    },
                    {
                        id: 3,
                        tname: '马刺',
                        age: 18
                    }
                ]

            }
        })



    </script>

</body>

</html>